package api

import "gitee.com/huanghua_2017/blade/state"

type CommonStruct struct {
	Internal struct {
		Version        func() string
		GetALiveConn   func() int64
		ProxyConnsInfo func() map[string]int64
		GetSlaveInfo   func() map[string]string
		SlaveConnsInfo func() []*state.SlaveConn
	}
}

type Common interface {
	Version() string
	GetALiveConn() int64
	ProxyConnsInfo() map[string]int64
	GetSlaveInfo() map[string]string
	SlaveConnsInfo() []*state.SlaveConn
}

type ClientStruct struct {
	CommonStruct
	Internal struct {
		StartSlave func(string, string) error
		StopSlave  func(string) error
	}
}

type Client interface {
	Common
	StartSlave(string, string) error
	StopSlave(string) error
}

type ServerStruct struct {
	CommonStruct
}

type Server interface {
	Common
}

func (slf *CommonStruct) Version() string {
	return slf.Internal.Version()
}

func (slf *CommonStruct) GetALiveConn() int64 {
	return slf.Internal.GetALiveConn()
}

func (slf *CommonStruct) ProxyConnsInfo() map[string]int64 {
	return slf.Internal.ProxyConnsInfo()
}

func (slf *CommonStruct) SlaveConnsInfo() []*state.SlaveConn {
	return slf.Internal.SlaveConnsInfo()
}

func (slf *CommonStruct) GetSlaveInfo() map[string]string {
	return slf.Internal.GetSlaveInfo()
}

func (slf *ClientStruct) StartSlave(laddr string, raddr string) error {
	return slf.Internal.StartSlave(laddr, raddr)
}

func (slf *ClientStruct) StopSlave(laddr string) error {
	return slf.Internal.StopSlave(laddr)
}
